<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增考勤管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
    	<div class="text-left hidden-print">
	        <button class="btn btn-primary" onclick="addProjectRow()"><i class="fa fa-edit"></i>选择主合同</button>
	    </div>
        <form class="form-horizontal m" id="form-kqproject-add">
            <h4 class="form-header h4">合同信息</h4>
            <input name="gysptProjectid" id="gysptProjectid" type="hidden">
            <input name="orderNo" id="orderNo" type="hidden">
            <input name="customerName" id="customerName" type="hidden">
            <input name="name" id="name" type="hidden">
            <input name="jshj" id="jshj" type="hidden">
            <input name="jig" id="jig" type="hidden">
            <input name="jfriq" id="jfriq" type="hidden">
            <input name="adress" id="adress" type="hidden">
            <input name="htype" id="htype" type="hidden">
            <input name="lxr" id="lxr" type="hidden">
            <input name="qdriq" id="qdriq" type="hidden">
            <input name="projectManager" id="projectManager" type="hidden">
            <input name="owner" id="owner" type="hidden">
            <div class="form-group">  
                <label class="col-sm-1 control-label">主合同编号：</label>
                <div class="col-sm-2">
                    <label id="orderNoStr" class="control-label"></label>
                </div>  
                <label class="col-sm-1 control-label">主合同名称：</label>
                <div class="col-sm-2">
                    <label id="nameStr" class="control-label"></label>
                </div> 
                <label class="col-sm-1 control-label">公司名称：</label>
                <div class="col-sm-2">
                    <label id="customerNameStr" class="control-label"></label>
                </div>
                <label class="col-sm-1 control-label">考勤机：</label>
                <div class="col-sm-2">
                    <select name="kqj" class="form-control" >
		                <option th:each="deili : ${deililis}" th:text="${deili.name}" th:value="${deili.id}"></option>
		            </select>
                </div>
            </div>
            <div class="form-group">  
                <label class="col-sm-1 control-label">价税合计：</label>
                <div class="col-sm-2">
                    <label id="jshjStr" class="control-label"></label>
                </div>
                <label class="col-sm-1 control-label ">交付日期：</label>
                <div class="col-sm-2">
                	<div class="input-group date">
                    	<label id="jfriqStr" class="control-label"></label>
                    </div>
                </div>
            	<label class="col-sm-1 control-label">项目地址：</label>
                <div class="col-sm-5">
                    <label id="adressStr" class="control-label"></label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 control-label">备注：</label>
                <div class="col-sm-11">
                    <textarea name="descs" class="form-control"></textarea>
                </div>
            </div>
            <h4 class="form-header h4">人员信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addSpkfkRow()"><i class="fa fa-plus"> 选择人员 </i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delRow()"><i class="fa fa-minus"> 删除 </i></button>
                    <div class="col-sm-12 select-table table-striped">
					    <table id="bootstrap-table"></table>
					</div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
          	<button type="button" class="btn btn-sm btn-primary" onclick="saveHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
          	<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>提 交</button>&nbsp;
          	<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:src="@{/js/math.min.js}"></script>
    <script th:src="@{/js/jquery.tmpl.js}"></script>
    <script th:inline="javascript">
        var prefix = ctx + "gcgl/kqproject"
        $("#form-kqproject-add").validate({
            focusCleanup: true
        });
        
        function saveHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/add", $('#form-kqproject-add').serialize());
            }
        }
        
        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/addSubmit", $('#form-kqproject-add').serialize());
            }
        }

        $("input[name='jfriq']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        /**商品单据**/
        $(function() {
        	
	    	// 初始化数据, 可以由后台传过来
		    var options = {
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
		        columns: [{
		            checkbox: true
		        },
		        {
		        	field: 'index',
		        	align: 'center',
		        	title: "序号",
		        	width:50,
                    formatter: function (value, row, index) {
                    	//var columnIndex = $.common.sprintf("<input type='hidden' name='items[%s].xuh' value='%s'>", $.table.serialNumber(index));
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	var columnpeopleId = $.common.sprintf("<input type='hidden' name='items[%s].peopleId' value='%s'>", index, row.peopleId);
		        		return columnIndex + $.table.serialNumber(index) + columnpeopleId;
                    }
                },
		        {
		            field: 'peopleName',
		            align: 'center',
		            title: '出工人员',
		            width:150,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].peopleName' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'phone',
		            align: 'center',
		            title: '联系电话',
		            width:150,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].phone' value='%s'>", index, value);
		        		return html +value;
                    }
		        },{
		            field: 'suosbz',
		            align: 'center',
		            title: '所属班组',
		            width:150,
		            formatter: function(value, row, index) {
		        		var data = [{ index: index, type: value }];
		                return $("#tmplbanz").tmpl(data).html();
                    }
		        },{
		            field: 'gongz',
		            align: 'center',
		            title: '工种',
		            width:150,
		            formatter: function(value, row, index) {
		        		var data = [{ index: index, type: value }];
		                return $("#tmplgongz").tmpl(data).html();
                    }
		        },{
		            field: 'banz',
		            align: 'center',
		            title: '班组长',
		            width:150,
		            formatter: function(value, row, index) {
		            	var html = $.common.sprintf("<input type='text' class='form-control' name='items[%s].banz' value='%s'>", index, value);
		        		return html;
                    }
		        },{
		        	field: 'id',
		            title: "操作",
		            align: "center",
		            width: 50,
		            formatter: function (value, row, index) {
		            	var html = $.common.sprintf("<input type='hidden' name='items[%s].id' value='%s'>", index, value);
		                var value = $.common.isNotEmpty(row.index)
		                  ? row.index
		                  : $.table.serialNumber(index);
		                return html+(
		                  '<a class="btn btn-danger btn-xs js-btn-delete" href="javascript:void(0)" onclick="removeGoods(\'' +
		                  value +
		                  '\', \'' +
		                  index +
		                  '\')"><i class="fa fa-remove"></i>删除</a>'
		                );
		            },
		        }]
		    };
		    $.table.init(options);
		});
        
        function addProjectRow() {
			var options = {
		       title: '选择主合同',
		       url: "/gcgl/kqproject/subProject",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitOrder
		    };
		    $.modal.openOptions(options);
		}
        
        function doSubmitOrder(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
          	//--------lable赋值
            $("#orderNoStr").text(rows[0].orderNo);
            $("#nameStr").text(rows[0].name);
            $("#customerNameStr").text(rows[0].customerName);
            $("#jigStr").text(rows[0].jig);
            $("#jshjStr").text(rows[0].jshj);
            $("#jfriqStr").text(rows[0].jfriq);
            $("#adressStr").text(rows[0].adress);
            
            //--------赋值
            $("#gysptProjectid").val(rows[0].id);
            $("#orderNo").val(rows[0].orderNo);
            $("#customerName").val(rows[0].customerName);
            $("#name").val(rows[0].name);
            $("#jshj").val(rows[0].jshj);
//             $("#jig").val(rows[0].jig);
            $("#jfriq").val(rows[0].jfriq);
            $("#adress").val(rows[0].adress);
            $("#htype").val(rows[0].htype);
            $("#lxr").val(rows[0].lxr);
            $("#qdriq").val(rows[0].qdriq);
            $("#projectManager").val(rows[0].projectManager);
            $("#owner").val(rows[0].owner);
            
            $.modal.closeAll();
        }
        
        //----------------
        // 删除按钮事件
        function removeGoods(value, index){
      	  sub.delRowByIndex(value);
        }

		function addSpkfkRow() {
			var options = {
		       title: '选择商品',
		       url: "/gcgl/kqproject/subPerson",
		       width: '1000',
		       height: '670',
		       callBack: doSubmitSpkfk
		    };
		    $.modal.openOptions(options);
		}
		
		function doSubmitSpkfk(index, layero){
            var rows = layero.find("iframe")[0].contentWindow.getSelections();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            for( i=0;i<rows.length;i++){
            	
            	var flag = 0;
            	var count = $("#" + table.options.id).bootstrapTable('getData').length;
            	var lis = $("#" + table.options.id).bootstrapTable('getData');
            	//判断是否重复
            	for(j=0;j<count;j++){
            		if(lis[j].id==rows[i].id){
            			flag = 1;
            			break;
            		}
            	}
            	if(flag==0){
            		var row = {
            			xh:i+1,
            			id: rows[i].id,
            			peopleName: rows[i].name,
            			peopleId: rows[i].id,
            			suosbz: rows[i].suosbz,
            			gongz: rows[i].gongz,
            			banz: '',
            			phone: rows[i].phone
                    }
                   	sub.addRow(row);
            	}
            }
            
            $.modal.closeAll();
        }

    </script>
</body>

<!-- 工种模板 -->
<script id="tmplgongz" type="text/x-jquery-tmpl">
<div>
<select class='form-control gongzstr' name='items[${index}].gongz' width='100px'>
<option value="1" {{if type=='1'}} selected {{/if}}>水电工</option>
<option value="2" {{if type=='2'}} selected {{/if}}>电工</option>
<option value="3" {{if type=='3'}} selected {{/if}}>瓦工</option>
<option value="4" {{if type=='4'}} selected {{/if}}>木工</option>
<option value="5" {{if type=='5'}} selected {{/if}}>油漆工</option>
<option value="6" {{if type=='6'}} selected {{/if}}>钢架工</option>
<option value="7" {{if type=='7'}} selected {{/if}}>石材工</option>
<option value="8" {{if type=='8'}} selected {{/if}}>龙骨工</option>
<option value="9" {{if type=='9'}} selected {{/if}}>普工</option>
<option value="10" {{if type=='10'}} selected {{/if}}>防水工</option>
<option value="11" {{if type=='11'}} selected {{/if}}>打孔开槽工</option>
<option value="12" {{if type=='12'}} selected {{/if}}>消防</option>
<option value="13" {{if type=='13'}} selected {{/if}}>暖通</option>
<option value="14" {{if type=='14'}} selected {{/if}}>环氧</option>
<option value="15" {{if type=='15'}} selected {{/if}}>玻璃</option>
<option value="16" {{if type=='16'}} selected {{/if}}>杂工</option>
<option value="17" {{if type=='17'}} selected {{/if}}>叉车工</option>
<option value="18" {{if type=='18'}} selected {{/if}}>电梯工</option>
<option value="19" {{if type=='19'}} selected {{/if}}>焊工</option>
<option value="20" {{if type=='20'}} selected {{/if}}>绿化工</option>
<option value="21" {{if type=='21'}} selected {{/if}}>架子工</option>
<option value="22" {{if type=='22'}} selected {{/if}}>措施工</option>
<option value="23" {{if type=='23'}} selected {{/if}}>安装工</option>
<option value="24" {{if type=='24'}} selected {{/if}}>木饰面安装工</option>
<option value="25" {{if type=='25'}} selected {{/if}}>石材安装工</option>
<option value="26" {{if type=='26'}} selected {{/if}}>铝板安装工</option>
<option value="27" {{if type=='27'}} selected {{/if}}>不锈钢安装工</option>
<option value="28" {{if type=='28'}} selected {{/if}}>玻璃安装工</option>
<option value="29" {{if type=='29'}} selected {{/if}}>GRG安装工</option>
<option value="30" {{if type=='30'}} selected {{/if}}>幕墙安装工</option>
<option value="31" {{if type=='31'}} selected {{/if}}>其他面层安装</option>
<option value="32" {{if type=='32'}} selected {{/if}}>起重机械</option>
<option value="33" {{if type=='33'}} selected {{/if}}>普通保洁</option>
<option value="34" {{if type=='34'}} selected {{/if}}>地板打蜡</option>
<option value="35" {{if type=='35'}} selected {{/if}}>结晶打磨</option>
<option value="36" {{if type=='36'}} selected {{/if}}>拆除</option>
<option value="37" {{if type=='37'}} selected {{/if}}>架构加固</option>
<option value="38" {{if type=='38'}} selected {{/if}}>打胶美缝</option>
<option value="39" {{if type=='39'}} selected {{/if}}>带班长</option>
<option value="40" {{if type=='40'}} selected {{/if}}>班组负责人</option>
<option value="41" {{if type=='41'}} selected {{/if}}>项目部管理人员</option>
<option value="42" {{if type=='42'}} selected {{/if}}>其他</option>
</select>
</div>
</script>

<!-- 班组模板 -->
<script id="tmplbanz" type="text/x-jquery-tmpl">
<div>
<select class='form-control banzstr' name='items[${index}].suosbz' width='100px'>
<option value="1" {{if type=='1'}} selected {{/if}}>木工</option>
<option value="2" {{if type=='2'}} selected {{/if}}>木饰面安装</option>
<option value="3" {{if type=='3'}} selected {{/if}}>木瓦油</option>
<option value="4" {{if type=='4'}} selected {{/if}}>弱电</option>
<option value="5" {{if type=='5'}} selected {{/if}}>石材安装/维修/打磨</option>
<option value="6" {{if type=='6'}} selected {{/if}}>铝板</option>
<option value="7" {{if type=='7'}} selected {{/if}}>石材</option>
<option value="8" {{if type=='8'}} selected {{/if}}>水电</option>
<option value="9" {{if type=='9'}} selected {{/if}}>泥瓦</option>
<option value="10" {{if type=='10'}} selected {{/if}}>打胶</option>
<option value="11" {{if type=='11'}} selected {{/if}}>乳胶漆</option>
<option value="12" {{if type=='12'}} selected {{/if}}>油漆</option>
<option value="13" {{if type=='13'}} selected {{/if}}>杂工</option>
<option value="14" {{if type=='14'}} selected {{/if}}>破拆</option>
<option value="15" {{if type=='15'}} selected {{/if}}>镶贴工</option>
<option value="16" {{if type=='16'}} selected {{/if}}>钢结构</option>
<option value="17" {{if type=='17'}} selected {{/if}}>焊工</option>
<option value="18" {{if type=='18'}} selected {{/if}}>美缝</option>
<option value="19" {{if type=='19'}} selected {{/if}}>打胶</option>
<option value="20" {{if type=='20'}} selected {{/if}}>贴膜</option>
<option value="21" {{if type=='21'}} selected {{/if}}>防水/防腐</option>
<option value="22" {{if type=='22'}} selected {{/if}}>木制品安装及维修</option>
<option value="23" {{if type=='23'}} selected {{/if}}>保洁</option>
<option value="24" {{if type=='24'}} selected {{/if}}>脚手架搭拆</option>
<option value="25" {{if type=='25'}} selected {{/if}}>绿化种植</option>
<option value="26" {{if type=='26'}} selected {{/if}}>幕墙安装作业</option>
<option value="27" {{if type=='27'}} selected {{/if}}>其他</option>
</select>
</div>
</script>

</html>